import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)



const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
		wxUserId: null
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorageSync('userInfo', provider)
			
			console.log("cache login:"+JSON.stringify(provider))
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorageSync('userInfo')
		},
		updateWxUserId(state, provider){
			state.wxUserId = ''+ provider.wxUserId;
		}
	},
	actions: {
	
	},
	getters: {
		getUserInfo(state) {
			state.userInfo = uni.getStorageSync('userInfo')
			return state.userInfo
		},
		getLoginStatus(state){
			return state.hasLogin;
		},
		getWxUserId(state){
			return state.wxUserId;
		}
		
	}
})

export default store
